const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const dllPath = 'public/dll';

module.exports = {
  entry: {
    vendor: ['./src/vendor.js'],
    vendor2: ['./src/vendor2.js']
  },
  output: {
    path: path.resolve(__dirname, dllPath),
    filename: '[name].dll.js', // name：vendor
    // vendor.dll.js中暴露出全局变量名
    // 保持与webpack.DllPlugin中名称一致 这一处必需与下一处相同
    library: '[name]_[hash]'
  },
  plugins: [
    // 清除之前的dll文件
    new CleanWebpackPlugin(),
    // manifest.json描述动态链接库包含了哪些内容
    new webpack.DllPlugin({
      path: path.join(__dirname, dllPath, '[name]-manifest.json'),
      // 保持与output.library中名称一致  这一处必需与上一处相同
      name: '[name]_[hash]',
      context: process.cwd() // 返回的是当前Node.js进程执行时的工作目录
    })
  ]
}